﻿using System; 
using System.Collections.Generic; 
using System.ComponentModel; 

namespace DataAccess{
[Serializable]
[GenWiseAttribute(IsDataSourceEntity = true) ]
public class art_tag : INotifyPropertyChanged
 {


#region --- Class Fields / Objects  ---

[NonSerialized]
protected PropertyChangedEventHandler _propertyChanged;
private System.Int32 _art_id;
private System.Int32 _tag_id;
private System.Int32? _number;
private art _art;
private tag _tag;

#endregion


#region --- Class Properties ---

public virtual System.Int32 art_id 
{
get
{
return _art_id;
}
set 
{
if ( _art_id != value) 
{
_art_id = value ;
OnPropertyChanged("art_id");
}
}
}

public virtual System.Int32 tag_id 
{
get
{
return _tag_id;
}
set 
{
if ( _tag_id != value) 
{
_tag_id = value ;
OnPropertyChanged("tag_id");
}
}
}

public virtual System.Int32? number 
{
get
{
return _number;
}
set 
{
if ( _number != value) 
{
_number = value ;
OnPropertyChanged("number");
}
}
}

/// <summary>
/// Generated from Relation FK_Art_tag_Art
/// </summary>
[GenWiseAttribute(RelationID = "4c42501e-7a88-478e-b1ba-f39351653d47") ]
public virtual art art 
{
get
{
if ( _art == null ) 
{
if (  _art_id.Equals(0)  || _art_id.Equals(System.Int32.MinValue) ) 
{
if ( _art != null && ( _art.id.Equals(System.Int32.MinValue) ) )
{
  _art = null;
}
}
else
{
_art = (new artFactory()).Get(_art_id);
}
}

return _art;
}
set 
{
if ( _art != value) 
{
if ( value==null ) _art_id = System.Int32.MinValue; else _art_id = (System.Int32)value.id; 
_art = value ;
}
}
}

/// <summary>
/// Generated from Relation FK_Art_tag_Tag
/// </summary>
[GenWiseAttribute(RelationID = "7f556224-66e4-43af-b14a-adaa13c45f18") ]
public virtual tag tag 
{
get
{
if ( _tag == null ) 
{
if (  _tag_id.Equals(0)  || _tag_id.Equals(System.Int32.MinValue) ) 
{
if ( _tag != null && ( _tag.id.Equals(System.Int32.MinValue) ) )
{
  _tag = null;
}
}
else
{
_tag = (new tagFactory()).Get(_tag_id);
}
}

return _tag;
}
set 
{
if ( _tag != value) 
{
if ( value==null ) _tag_id = System.Int32.MinValue; else _tag_id = (System.Int32)value.id; 
_tag = value ;
}
}
}

/// <summary>
/// Property that simulates a unique PK by concatenating all the Pk properties
/// </summary>
public virtual System.String VirtualPk 
{
get
{
string _retValue = string.Empty;

_retValue += art_id.ToString();

_retValue += "^";
_retValue += tag_id.ToString();

return _retValue;

}
}

/// <summary>
/// Is this object Valid? 
/// </summary>
/// <remarks>
/// This is achieved by counting how many errors are returned from the Validate() method. If no errors are found then it's valid.
/// </remarks>
[Bindable(false)]
public virtual System.Boolean IsValid 
{
get
{
List<Error> _errors = this.Validate(); if ( _errors.Count > 0 ) return false; else return true;
}
}


#endregion


#region --- Class Methods --- 

/// <summary>
/// Raises PropertyChanged event.
/// </summary>
protected virtual void OnPropertyChanged(System.String ppropertyChanged)
{
if (_propertyChanged != null) _propertyChanged( this , new PropertyChangedEventArgs(ppropertyChanged));

}

/// <summary>
/// Create a new art_tag object. 
/// </summary>
public  art_tag()
{
}

/// <summary>
/// Create a new instance/object
/// </summary>
public  art_tag(System.Int32 part_id , System.Int32 ptag_id)
{
_art_id = part_id ;
_tag_id = ptag_id ;

}

public override int GetHashCode()
{
string _hash = String.Empty; 
_hash += art_id.ToString();
_hash += tag_id.ToString();
return _hash.GetHashCode(); 

}

public override bool Equals(object pobject)
{
art_tag _newart_tag = (pobject as art_tag); 
if (_newart_tag == null ) return false; 
if (_newart_tag.GetHashCode() == this.GetHashCode() ) return true; 
return false; 

}

/// <summary>
/// Validates the object returning a list of errors if the validation fails.
/// </summary>
/// <remarks>
/// You can use the provided User CodeBlocks to add your own validations.
/// </remarks>
///<returns>Returns the List of Errors found during the Validation. If no errors are found null is returned.<returns>
public virtual List<Error> Validate()
{
List<Error> _errors = new List<Error>();

// Primary Key Validation (Template Option)
if (  art_id.Equals(0)  ) 
{
   _errors.Add( new Error( "The PK Column (art_id) can not be null!. " ) );
}
if (  tag_id.Equals(0)  ) 
{
   _errors.Add( new Error( "The PK Column (tag_id) can not be null!. " ) );
}

return _errors;
}


#endregion


#region --- Class Events  ---

public event PropertyChangedEventHandler PropertyChanged 
{
   add {
_propertyChanged+= value;
   }
   remove {
_propertyChanged-= value;
   }
}


#endregion
}
}

